package com.servlet;

import com.dao.*;
import com.entity.admin;
import com.entity.user;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class gLogin extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=req.getParameter("name");
        String pwd=req.getParameter("pwd");
        logindao l=new logindaoimpl();
        if(l.gLogin(id,pwd))
        {
            Cookie cookie=new Cookie("gldl","yes");
            resp.addCookie(cookie);
            req.getRequestDispatcher("/houtai.jsp").forward(req,resp);
        }
        else if(!(l.gLogin(id,pwd)))
        {
            req.setAttribute("message","用户名或密码不正确");
            req.getRequestDispatcher("/gldenglu.jsp").forward(req,resp);
        }
    }
}
